package com.mo;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.EnableMBeanExport;
import org.springframework.context.annotation.Import;
import org.springframework.jmx.support.RegistrationPolicy;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;

import com.github.tobato.fastdfs.FdfsClientConfig;
import com.mo.config.properties.MoProperties;

/**
 * SpringBoot方式启动类
 *
 * @author chenxiaodong
 * @Date 2017/5/21 12:06
 */
@EnableMBeanExport(registration = RegistrationPolicy.IGNORE_EXISTING)
@Import(FdfsClientConfig.class)
@SpringBootApplication
public class MoApplication extends HessianServletInitializer{

    protected final static Logger logger = LoggerFactory.getLogger(MoApplication.class);

    @Autowired
    MoProperties MoProperties;

    
    /**
     * 增加swagger的支持 添加图文详情图片位置映射
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        if(MoProperties.getSwaggerOpen()){
            registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
            registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
            registry.addResourceHandler("/MP_verify_PgPANut04w3d6vg9.txt").addResourceLocations("classpath:/META-INF/");
        }
        /*String fileSavePath = MoProperties.getFileUploadPath();
        if(!fileSavePath.endsWith("/")){
        	fileSavePath += "/";
        }
        String urlMappingImgpath = MoProperties.getUrlMappingImgpath();//"/static/uploadImage/"
        //添加图文详情图片位置映射
        registry.addResourceHandler(urlMappingImgpath+"**").addResourceLocations("file:///"+fileSavePath);*/
        
        /*String apkUploadPath = MoProperties.getApkUploadPath();
        if(!apkUploadPath.endsWith("/")){
        	apkUploadPath += "/";
        }
        String urlMappingApkpath = MoProperties.getUrlMappingApkpath();
        //添加APK位置映射
        registry.addResourceHandler(urlMappingApkpath+"**").addResourceLocations("file:///"+apkUploadPath);*/
    }

    public static void main(String[] args) {
        SpringApplication.run(MoApplication.class, args); 
        logger.info("moApplication is success!");
    }
 
       
}
